/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs.panel.grid.column;

import org.rails.extjs.AbsBase;
import org.rails.extjs.form.Field;
import org.rails.extjs.javascript.Function;

public class Column extends AbsBase {
	
	public Column() {
		super();
	}

	public Column(String dataIndex,String header) {
		super();
		setHeader(header);
		setDataIndex(dataIndex);
	}

	public void setAlign(String align) {
		addOption("align", align);
	}

	public String getAlign() {
		return getString("align", "");
	}

	public void setCss(String css) {
		addOption("css", css);
	}

	public String getCss() {
		return getString("css", "");
	}

	private void setDataIndex(String dataIndex) {
		addOption("dataIndex", dataIndex);
	}

	public String getDataIndex() {
		return getString("dataIndex", "");
	}

	public void setEditable(Boolean editable) {
		addOption("editable", editable);
	}

	public Boolean isEditable() {
		return getBoolean("editable", true);
	}

	public void setEditor(Field editor) {
		addOption("editor", editor);
	}

	public Field getEditor() {
		return (Field) getOption("editor");
	}

	public void setEmptyGroupText(String emptyGroupText) {
		addOption("emptyGroupText", emptyGroupText);
	}

	public String getEmptyGroupText() {
		return getString("emptyGroupText", "");
	}

	public void setFixed(Boolean fixed) {
		addOption("fixed", fixed);
	}

	public Boolean isFixed() {
		return getBoolean("fixed", false);
	}

	public void setGroupName(String groupName) {
		addOption("groupName", groupName);
	}

	public String getGroupName() {
		return getString("groupName", "");
	}

	public void setGroupRenderer(Function groupRenderer) {
		addOption("groupRenderer", groupRenderer);
	}

	public Function getGroupRenderer() {
		return (Function) getOption("groupRenderer");
	}

	public void setGroupable(Boolean groupable) {
		addOption("groupable", groupable);
	}

	public Boolean isGroupable() {
		return getBoolean("groupable", true);
	}

	protected void setHeader(String header) {
		addOption("header", header);
	}

	public String getHeader() {
		return getString("header", "");
	}

	public void setHidden(Boolean hidden) {
		addOption("hidden", hidden);
	}

	public Boolean isHidden() {
		return getBoolean("hidden", false);
	}

	public void setHideable(Boolean hideable) {
		addOption("hideable", hideable);
	}

	public Boolean isHideable() {
		return getBoolean("hideable", true);
	}

	public void setId(String id) {
		addOption("id", id);
	}

	public String getId() {
		return getString("id", "");
	}

	public void setMenuDisabled(Boolean menuDisabled) {
		addOption("menuDisabled", menuDisabled);
	}

	public Boolean isMenuDisabled() {
		return getBoolean("menuDisabled", false);
	}

	public void setResizable(Boolean resizable) {
		addOption("resizable", resizable);
	}

	public Boolean isResizable() {
		return getBoolean("resizable", true);
	}

	public void setSortable(Boolean sortable) {
		addOption("sortable", sortable);
	}

	public Boolean isSortable() {
		return getBoolean("sortable", true);
	}

	public void setTooltip(String tooltip) {
		addOption("tooltip", tooltip);
	}

	public String getTooltip(String tooltip) {
		return getString("tooltip", "");
	}
	
	public void setWidth(Number width){
		addOption("width", width);
	}
	
	public void setRenderer(Function renderer){
		addOption("renderer", renderer);
	}
	
	public Function getRenderer(){
		return (Function)getOption("renderer");
	}

	@Override
	public String getScript() {
		script = new StringBuffer("");
		script.append("new Ext.grid.Column(");
		script.append(createOptions());
		script.append(")");
		return script.toString();
	}

}
